const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
let app = express();
app.listen(3000);


//设置跨域访问
app.all("*",function(req,res,next){
    //设置允许跨域的域名，*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin","http://localhost:5003");
    //允许的header类型
    res.header("Access-Control-Allow-Headers","content-type");
    //如果跨域要获取cookie必须加上
    res.header("Access-Control-Allow-Credentials","true");
    //跨域允许的请求方式 
    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
    
    if (req.method.toLowerCase() == 'options')
        res.send(200);  //让options尝试请求快速结束
    else
        next();
})

app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true })); //extended: true：表示使用第三方模块qs来处理
app.use(require('./pro-api.js')); 
app.use(require('./user-api.js'));
app.use(require('./cart-api.js'));
app.use(require('./address-api.js'));

